home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / packet / p_aa4re / bb212src / ax25.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1987-09-29  |  12.6 KB  |  235 lines

  1. (*========================================================================*)
  2. (* AX25 Level 2 protocol                                                  *)
  3. (*                                                                         *)
  4. (*  Copyright 1986, 1987 by H. Roy Engehausen.  All rights reserved.       *)
  5. (*  This software may be freely distributed and used, but it may not       *)
  6. (*  under any circumstances be sold by anyone other than the author.       *)
  7. (*  It may be distributed by a commercial company as long as it is         *)
  8. (*  for no cost.                                                           *)
  9. (*                                                                         *)
  10. (*========================================================================*)
  11.  
  12. CONST
  13.   max_ax25_digipeaters = 8;         (* Max digipeater count               *)
  14.  
  15.   max_ax25_address     = 11;        (* Max addresses in ax25 header + 1   *)
  16.                                     (*           dest , source, 8 digis   *)
  17.  
  18.   call_sign_length     = 6;         (* Length of the name section of addr *)
  19.  
  20.   address_field_length = 7;         (* Length of the whole address field  *)
  21.  
  22.   ssid_max             = 15;        (* Highest allowable ssid             *)
  23.  
  24. (*------------------------------------------------------------------------*)
  25. (* Address field.  This is variable length.                               *)
  26. (*------------------------------------------------------------------------*)
  27.  
  28. TYPE
  29.  
  30.     address_field = RECORD
  31.                       name        : ARRAY[1..call_sign_length] of CHAR;
  32.                       addr_flag   : BYTE;
  33.                     END;
  34.  
  35.     address_1     = RECORD        (* This type is used for SIZEOF        *)
  36.                       dest        : address_field;
  37.                       source      : address_field;
  38.                     END;
  39.  
  40.     address_area  = RECORD
  41.                       dest        : address_field;
  42.                       source      : address_field;
  43.                       repeaters   : ARRAY[1..max_ax25_digipeaters]
  44.                                                            OF address_field;
  45.                     END;
  46.  
  47.     call_field    = ARRAY[1..call_sign_length] OF CHAR;
  48.  
  49.     address_over  = ARRAY[1..max_ax25_address] OF address_field;
  50.  
  51.     address_area_ptr_type = ^address_area;
  52.  
  53. (*------------------------------------------------------------------------*)
  54. (* Control byte                                                           *)
  55. (*------------------------------------------------------------------------*)
  56.  
  57. TYPE
  58.  
  59.     control_field = BYTE;
  60.  
  61. (*------------------------------------------------------------------------*)
  62. (* Protocol identification byte                                           *)
  63. (*------------------------------------------------------------------------*)
  64.  
  65. TYPE
  66.  
  67.     pid_field     = BYTE;
  68.  
  69. (*------------------------------------------------------------------------*)
  70. (* Data area                                                              *)
  71. (*------------------------------------------------------------------------*)
  72.  
  73. TYPE
  74.  
  75.     data_field    = ARRAY[1..512] OF CHAR;
  76.  
  77. (*------------------------------------------------------------------------*)
  78. (* Combination of last three areas.  They are always in this order        *)
  79. (* and the same size                                                      *)
  80. (*------------------------------------------------------------------------*)
  81.  
  82. TYPE
  83.  
  84.     packet_data   = RECORD
  85.                       control_packet : control_field;
  86.                       pid_packet     : pid_field;
  87.                       data_packet    : data_field;
  88.                     END;
  89.  
  90. (*------------------------------------------------------------------------*)
  91. (* Definition of addr_flag                                                *)
  92. (*       x....... = H flag (repeated -- only in digi addresses)           *)
  93. (*       x....... = C flag (Only in source and destination addresses)     *)
  94. (*       .xx..... = reserved (must be one)                                *)
  95. (*       ...xxxx. = ssid                                                  *)
  96. (*       .......x = E flag (end address)                                  *)
  97. (*------------------------------------------------------------------------*)
  98.  
  99. CONST
  100.  
  101.     flag_e      = $01;
  102.     flag_ssid   = $1E;
  103.     flag_reser  = $60;
  104.     flag_h      = $80;
  105.     flag_c      = $80;
  106.     flag_ssid_shift = 1;            (* Shift factor for SSID              *)
  107.  
  108. (*------------------------------------------------------------------------*)
  109. (* Definition of control field                                            *)
  110. (*                                                                        *)
  111. (*       .......0 = I frame                                               *)
  112. (*       ....xxx. = N(S)                                                  *)
  113. (*       ...x ... = P/F                                                   *)
  114. (*       xxx..... = N(R)                                                  *)
  115. (*                                                                        *)
  116. (*       ......01 = S frame                                               *)
  117. (*       ....0001 =   RR                                                  *)
  118. (*       ....0101 =   RNR                                                 *)
  119. (*       ....1001 =   Reject                                              *)
  120. (*       ...x.... = P/F                                                   *)
  121. (*       xxx..... = N(R)                                                  *)
  122. (*                                                                        *)
  123. (*       ......11 = U frame                                               *)
  124. (*       000.0011 =   Unnumbered information                              *)
  125. (*       000.1111 =   DM (busy)                                           *)
  126. (*       001.1111 =   SABM                                                *)
  127. (*       010.0011 =   Disconnect                                          *)
  128. (*       011.0011 =   Unnumbered Ack                                      *)
  129. (*       100.0111 =   FRMR Frame reject                                   *)
  130. (*       ...x.... = P/F                                                   *)
  131. (*------------------------------------------------------------------------*)
  132.  
  133. CONST
  134.  
  135.     control_su   = $03;              (* I/S/U frame bits                  *)
  136.     control_if1  = $00;              (*   I frame                         *)
  137.     control_if2  = $02;              (*   Also an I frame                 *)
  138.     control_sf   = $01;              (*   S frame                         *)
  139.     control_uf   = $03;              (*   U frame                         *)
  140.  
  141.     control_pf   = $10;              (* Mask for P/F                      *)
  142.  
  143.     control_ns   = $0E;              (* Mask for N(S)                     *)
  144.     control_ns_shift = 1;            (* Shift for N(S)                    *)
  145.     control_nr   = $E0;              (* Mask for N(R)                     *)
  146.     control_nr_shift = 5;            (* Shift for N(R)                    *)
  147.  
  148.     control_sm   = $0F;              (* S frame mask                      *)
  149.     control_rr   = $01;              (* S frame, RR                       *)
  150.     control_rnr  = $05;              (* S frame, RNR                      *)
  151.     control_rej  = $09;              (* S frame, Rejected                 *)
  152.  
  153.     control_um   = $EF;              (* U frame mask                      *)
  154.     control_ui   = $03;              (* U frame, UI                       *)
  155.     control_dm   = $0F;              (* U frame, DM                       *)
  156.     control_sabm = $2F;              (* U frame, SABM                     *)
  157.     control_disc = $43;              (* U frame, Disconnect               *)
  158.     control_ua   = $63;              (* U frame, Ack                      *)
  159.     control_frmr = $87;              (* U frame, FRMR                     *)
  160.  
  161. (*------------------------------------------------------------------------*)
  162. (* Definition of protocol field                                           *)
  163. (*                                                                        *)
  164. (*    These values are actually assigned                                  *)
  165. (*                                                                        *)
  166. (*       11001100 = Internet Protocol datagram layer 3                    *)
  167. (*       11001101 = Address Resolution protocol layer 3                   *)
  168. (*       11110000 = No layer 3                                            *)
  169. (*       11111111 = Next character has more information                   *)
  170. (*                                                                        *)
  171. (*    These are indicative of how this byte will be used in the future    *)
  172. (*                                                                        *)
  173. (*       ..00.... = Reserved                                              *)
  174. (*       ..01.... = AX.25 Level 3                                         *)
  175. (*       ..10.... = AX.25 Level 3                                         *)
  176. (*       ..11.... = Reserved                                              *)
  177. (*------------------------------------------------------------------------*)
  178.  
  179. CONST
  180.  
  181.     protocol_ipd = $CC;              (* Internet                          *)
  182.     protocol_arp = $CD;              (* Address resolution                *)
  183.     protocol_no3 = $F0;              (* No layer 3                        *)
  184.     protocol_mor = $F0;              (* No layer 3                        *)
  185.  
  186.     protocol_kay = $30;              (* Layer mask                        *)
  187.     protocol_x30 = $00;              (* ??????????                        *)
  188.     protocol_x31 = $10;              (* AX level 3                        *)
  189.     protocol_x32 = $20;              (* AX level 3                        *)
  190.     protocol_x33 = $30;              (* ??????????                        *)
  191.  
  192. (*------------------------------------------------------------------------*)
  193. (* Definition of "C" field.  This consists of the two "C" bits, one       *)
  194. (*   on the destination and one on the source.  The equates below are     *)
  195. (*   for both bits in that order.                                         *)
  196. (*                                                                        *)
  197. (*   00 = Version 1                                                       *)
  198. (*   01 = Version 2 Response                                              *)
  199. (*   10 = Version 2 Command                                               *)
  200. (*   11 = Version 1                                                       *)
  201. (*------------------------------------------------------------------------*)
  202.  
  203. CONST
  204.  
  205.     cfield_v11   = $00;              (* Version 1                         *)
  206.     cfield_v2r   = $01;              (* Version 2 response                *)
  207.     cfield_v2c   = $02;              (* Version 1 command                 *)
  208.     cfield_v12   = $03;              (* Version 1                         *)
  209.  
  210.     cfield_dm    = $02;              (* Destination Mask                  *)
  211.     cfield_sm    = $01;              (* Source Mask                       *)
  212.  
  213. (*------------------------------------------------------------------------*)
  214. (* State diagram for links                                                *)
  215. (*------------------------------------------------------------------------*)
  216.  
  217. TYPE
  218.     link_state_type = (link_s1,      (* Disconnected                      *)
  219.                        link_s2,      (* Link setup                        *)
  220.                        link_s3,      (* Frame reject                      *)
  221.                        link_s4,      (* Disconnect request                *)
  222.                        link_s5,      (* Information transfer              *)
  223.                        link_s6,      (* REJ frame sent                    *)
  224.                        link_s7,      (* Waiting ACK                       *)
  225.                        link_s8,      (* Device busy                       *)
  226.                        link_s9,      (* Remote device busy                *)
  227.                        link_s10,     (* Both devices busy                 *)
  228.                        link_s11,     (* Waiting ACK and device busy       *)
  229.                        link_s12,     (* Waiting ACK and remote busy       *)
  230.                        link_s13,     (* Waiting ACK and both busy         *)
  231.                        link_s14,     (* REJ sent and device busy          *)
  232.                        link_s15,     (* REJ sent and remote busy          *)
  233.                        link_s16);    (* REJ sent and both busy            *)
  234.  
  235.